home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 25
/
Mac Magazin and MacEasy Magazine CD - Issue 25.iso
/
Online
/
Joe's-E-mail-Scripts
/
Speaking E-mail
/
Speaking E-mail (text)
< prev
Wrap
Text File
|
1996-08-20
|
6KB
|
188 lines
global serverResponse, sss, inBox
on run
set closeAfter to false
if not (PPPopened) then
set closeAfter to true
openPPP (getPPPServer)
repeat while not (PPPopened)
end repeat
end if
set sss to (tcp connect to host (GetICPreference SMTP host) port 110)
try
readresponse(sss)
tcp write data "USER " & (GetICPreference mail account) & return stream sss using ISO88591
readresponse(sss)
tcp write data "PASS " & (GetICPreference mail password) & return stream sss using ISO88591
readresponse(sss)
tcp write data "STAT" & return stream sss using ISO88591
readresponse(sss)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set messageCount to text item 2 of serverResponse as integer
set AppleScript's text item delimiters to oldDelimiters
if messageCount ≠ 0 then
if messageCount = 1 then
speak "There is one message"
else
speak "There are " & messageCount & " new messages"
end if
tell application "Finder"
if not (folder "AppleScript Inbox" of desktop exists) then
set inBox to (make folder with properties {name:"AppleScript Inbox"}) as string
else
set inBox to (folder "AppleScript Inbox" of desktop) as string
end if
end tell
set currentMessage to 1
repeat while currentMessage ≤ messageCount
getMail(currentMessage)
set currentMessage to currentMessage + 1
end repeat
else
speak "There are no messages"
end if
tcp close stream sss
on error msg number num
tcp close stream sss
display dialog "Error. Script Aborted." buttons {"OK"} default button "OK"
quit
end try
if closeAfter = true then
if (PPPopened) = true then
closePPP with hard close
end if
end if
end run
on open (docList)
set messageCount to (count of docList) as string
if messageCount ≠ "1" then
speak messageCount & " messages to be sent"
else
speak "one message to be sent"
end if
set closeAfter to false
if not (PPPopened) then
set closeAfter to true
openPPP (getPPPServer)
repeat while not (PPPopened)
end repeat
end if
set LF to ASCII character (10)
set CR to return
set CRLF to CR & LF
set sss to (tcp connect to host (GetICPreference SMTP host) port 25)
readresponse(sss)
tcp write data "HELO " & (tcp my address) & return stream sss using ISO88591
readresponse(sss)
try
repeat with aFile in docList
set aFile to contents of aFile
tcp write data "mail from: " & (GetICPreference mail account) & return ¬
stream sss using ISO88591
readresponse(sss)
set afilename to aFile as string
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set theFileName to last text item of afilename
set AppleScript's text item delimiters to oldDelimiters
set emailSubject to theFileName as text
open for access afilename
set sendToaddress to (read afilename before return)
set mailContents to (read afilename)
close access afilename
tcp write data "rcpt to: " & sendToaddress & return ¬
stream sss using ISO88591
readresponse(sss)
tcp write data "data" & return stream sss using ISO88591
readresponse(sss)
tcp write data "To: " & sendToaddress & return stream sss using ISO88591
tcp write data "Subject: " & emailSubject & return stream sss using ISO88591
tcp write data mailContents & return stream sss using ISO88591
tcp write data "." & return stream sss using ISO88591
readresponse(sss)
end repeat
tcp close stream sss
speak "transmission completed"
if closeAfter = true then
if (PPPopened) = true then
closePPP with hard close
end if
end if
return
on error msg number num
tcp close stream sss
display dialog "Error. Script Aborted." buttons {"OK"} default button "OK"
quit
end try
end open
on getMail(currentMessage)
set LF to ASCII character (10)
set nowTotal to (time string of (current date))
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set nowHour to text item 1 of nowTotal
set nowMin to text item 2 of nowTotal
set nowSec to text item 3 of nowTotal
set nowString to nowHour & "h" & nowMin & "m" & nowSec & "s"
set AppleScript's text item delimiters to oldDelimiters
set currentFilename to inBox & "Message #" & currentMessage & " " & nowString
open for access file currentFilename with write permission
tcp write data "RETR " & currentMessage & return stream sss using ISO88591
readresponse(sss)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set messageSize to text item 2 of serverResponse as integer
set AppleScript's text item delimiters to oldDelimiters
repeat until (bytes waiting of (tcp status stream sss) = 0)
write (tcp read stream sss using ISO88591) to file currentFilename starting at eof
set beginWait to time of (current date)
repeat until time of (current date) > beginWait + 1
end repeat
end repeat
if (get eof currentFilename) > messageSize * 0.75 then
tcp write data "DELE " & currentMessage & return stream sss using ISO88591
readresponse(sss)
end if
close access file currentFilename
end getMail
on readresponse(sstream)
set LF to ASCII character (10)
repeat until (tcp ahead characters LF stream sstream)
end repeat
set serverResponse to (tcp read until characters LF stream sstream using ISO88591)
end readresponse
on quit
continue quit
end quit